//
//  PreviewActivityView.m
//  ICrEAM
//
//  Created by kuroro on 16/11/18.
//  Copyright © 2016年 mac. All rights reserved.
//

#import "PreviewActivityView.h"
#import "PreviewActivityViewCell.h"
#import "ICMActivityModel.h"
@implementation PreviewActivityView

+(instancetype)creatWithFrame:(CGRect)frame dataSource:(NSArray *)dataSource{
    return [[PreviewActivityView alloc]initWithFrame:frame dataSource:dataSource];
}

-(instancetype)initWithFrame:(CGRect)frame dataSource:(NSArray *)dataSource{
    if (self = [super initWithFrame:frame]) {
        self.dataArray = dataSource;
        UITableView *tableView = [[UITableView alloc]initWithFrame:CGRectMake(ActualWidth(60), 0, ScreenWidth-ActualWidth(60), ActualHeight(120))];
        tableView.delegate = self;
        tableView.dataSource = self;
        tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        [tableView registerNib: [UINib nibWithNibName:@"PreviewActivityViewCell" bundle:nil]
        forCellReuseIdentifier:@"PreviewActivityViewCell"];
        tableView.bounces = NO;
        [self addSubview:tableView];
    }
    return self;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return  self.dataArray.count;
}

- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    PreviewActivityViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"PreviewActivityViewCell"];
    if (!cell) {
        cell = [[PreviewActivityViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"PreviewActivityViewCell"];
    }
    ICMActivityItemModel *model = self.dataArray[indexPath.row];
    cell.name.text = model.ACTIVITY_NAME;
    cell.code.text = model.ACTIVITY_CODE;
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return ActualHeight(40);
}


@end
